<%@ page contentType="text/html;charset=UTF-8" language="java" pageEncoding="UTF-8" %>

<table id="constant_table" class="table table-bordered">
</table>
<script type="text/javascript">
    $(function () {
        var table_cl = $('#constant_table').datagrid({
            height: '100%',
            width:'100%',
            fullGrid:true,
            columnMenu: false,
            contextMenuH:false,
            fieldSortable:false,
            gridTitle: '系统常量',
            showToolbar: true,
            toolbarCustom:function(){
                return '<button type="button" class="btn btn-blue" onclick="saveConstant();" data-icon="plus"><i class="fa fa-plus"></i> 添加</button>';
            },
            toolbarItem:"refresh,|,del",
            filterThead: false,
            delPK: 'id',
            dataUrl: '/admin/constant/constants',
            local: "remote",
            inlineEditMult: false,
            saveAll: false,
            addLocation: 'last',
            editUrl: '/admin/constant/save',
            delUrl: '/admin/constant/delete',
            delConfirm:true,
            delCallback: function (response) {
                if (response.haveError) {
                    BJUI.alertmsg('error', response.errMsg, {
                        okCall: function () {
                            BJUI.navtab('refresh')
                        }
                    });
                } else {
                    BJUI.alertmsg('ok', response.data, {
                        okCall: function () {
                            BJUI.navtab('refresh')
                        }
                    });
                }
            },
            columns: [
                {
                    name: 'name',
                    label: '配置名称',
                    align: 'center',
                    rule:  'required',
                    add:false
                },  {
                    name: 'nid',
                    label: '标识',
                    align: 'center',
                    rule:  'required',
                    add:false
                },{
                    name: 'value',
                    label: '配置值',
                    align: 'center',
                    add:false
                },{
                    name: 'remark',
                    label: '说明',
                    align: 'center'
                }, {
                    render: operation,
                    label: '操作列'
                }
            ],
            paging: {pageSize: 20, pageIndex: 1},
            linenumberAll: true
        });

    });

    function operation(value, data) {
        var html = '<button type="button" class="btn-green" onclick="saveConstant(\''+data.id+'\');">编辑</button>'
            + '<button type="button" class="btn-red" data-toggle="del.datagrid.tr">删除</button>';
        return html
    }

    function saveConstant(id){
        var url = "/admin/constant/savePage";
        if(id!=""&&id!=null&&typeof (id) != "undefined" ){
            url = url + "?id="+id;
        }
        BJUI.dialog({
            id: 'save_constant',
            url: url,
            title: '编辑',
            resizable: true,
            width: 465,
            height: 325,
            fresh:true
        });
    }
</script>